#ifndef _CMODULE_H_
#define _CMODULE_H_

#include "CQue.h"
#include "CSem.h"
#include "CTask.h"

#ifdef __cplusplus
extern "C" {
#endif

#include <cmd_def.h>

#define MODULE_NAME_MAX				31
#define USE_DEFAULT_MODULE_ENTRY    0

typedef struct _cmsg_ {
	unsigned short msg_id;
    unsigned short data_len;    //msg_id = the real .data len
    char data[1]; //dummy
} CMsg;

typedef struct _cmodule_ {
	//attribute
	CQue q;
	CSem sem;
	CTask th;
	char module_name[MODULE_NAME_MAX + 1];

	//action
	int(*run)(struct _cmodule_*);
	int(*sendMsg)(struct _cmodule_*, CMsg*);
    int(*exeMsg)(struct _cmodule_*, CMsg* msg);
} CModule;
typedef int(*MODULE_EXEMSG_FN)(struct _cmodule_*, CMsg* msg);

int construct_module(CModule* md, const char* module_name, MODULE_EXEMSG_FN onMsg);

#ifdef __cplusplus
}
#endif
#endif
